<?php

class App {

	private static $_application = NULL;
//	private static $_componentConfigs = array();
    private static $_runningWebsite = NULL;
    public static function getRunningWebsite(){
        if(is_null(self::$_runningWebsite)){
            self::$_runningWebsite = Soul_Request_Context::getInstance()->getRunningWebsite();
        }
        return self::$_runningWebsite;
    }
    
    public static function loadModel($name, $id){
		return self::getModel($name)->load($id);
    }    
    
    public static function getModel($name){
        if (strpos($name, '/')) {
            return Soul_Loader::loadInstance('component_' . str_replace('/', '_model_', $name));
        }
        return Soul_Loader::loadInstance($name);
    }
    
    public static function getBusiness($name){
        if (strpos($name, '/')) {
            return Soul_Loader::loadSingleton('component_' . str_replace('/', '_business_', $name));
        }
        return Soul_Loader::loadSingleton($name);
    }
    
//    public static function getConfig($name){
//        if(isset(self::$_componentConfigs[$name])){
//            return new Soul_Object(self::$_componentConfigs[$name]);
//        }
//        return NULL;
//    }

    public static function runHttp() {
        self::$_application = Soul_Request_Factory::getHttpApplication();
        self::$_application->run();
    }

   public static function runCommand() {
        self::initialize();
        self::$_application = Soul_Web_Factory::getApplication();
        self::$_application->setConfig(Soul_Util_Yaml::parseFile(DP_CONFIG . FP_APP_CONFIG));
        self::$_application->run();
    }
}